package com.info.zhiduoduo.admin.controller;

import com.info.zhiduoduo.admin.model.formbean.scheduletask.SwitchTaskFormBean;
import com.info.zhiduoduo.admin.service.SystemScheduleTaskService;
import com.info.zhiduoduo.common.annotation.LogEntity;
import com.info.zhiduoduo.common.annotation.LogParameter;
import com.info.zhiduoduo.common.annotation.ZddLog;
import com.info.zhiduoduo.common.constants.SmartResult;
import com.info.zhiduoduo.common.constants.system.ZddLogType;
import com.info.zhiduoduo.common.formbean.BaseSimpleFormBean;
import com.info.zhiduoduo.repository.entity.system.SystemScheduleTask;
import com.info.zhiduoduo.repository.entity.system.SystemScheduleTaskItem;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/system/scheduleTask")
public class SystemScheduleTaskController {

	@Autowired
	SystemScheduleTaskService systemScheduleTaskService;

	@ApiOperation("获取定时任务列表")
	@PostMapping("/listTasks")
	public SmartResult<SystemScheduleTask> listTasks(@RequestBody BaseSimpleFormBean<String> formBean) {
		return systemScheduleTaskService.listTasks(formBean);
	}

	@ZddLog(type = ZddLogType.UPDATE,name = "开启/关闭定时任务",entities = @LogEntity(entity = SystemScheduleTask.class,parameters =
	@LogParameter(fields = "id",parameters = "formBean.reqdata.id")))
	@ApiOperation("开启/关闭定时任务")
	@PostMapping("/switchTask")
	public SmartResult switchTask(@RequestBody @Valid BaseSimpleFormBean<SwitchTaskFormBean> formBean) {
		return systemScheduleTaskService.switchTask(formBean);
	}

	@ApiOperation(value = "获取定时任务执行详情", notes = "reqdata: task 主键id")
	@PostMapping("/listTaskItems")
	public SmartResult<SystemScheduleTaskItem> listTaskItems(@RequestBody BaseSimpleFormBean<Integer> formBean) {
		return systemScheduleTaskService.listTaskItems(formBean);
	}
}
